/*
 * Double_Buffer.h
 *
 *  Created on: Mar 7, 2012
 *      Author: ajeffery
 */

#include <stdint.h>
#include <native/mutex.h>
#include <native/cond.h>
#include "defs.h"

#ifndef DOUBLE_BUFFER_H_
#define DOUBLE_BUFFER_H_

typedef struct status{
	uint8_t position;
	uint8_t dest;
	uint8_t current_calls[MAX_FLOORS];
}status_t;

typedef struct statusBuffer{
	status data[BUFFER_SIZE];
}stat_buffer_t;

class Double_Buffer {
public:
	Double_Buffer();
	virtual ~Double_Buffer();

	status_t get(int buffId);

	void put(status_t *data);

private:
	status_t buffer[2][BUFFER_SIZE];
	int index[2];
	int length[2];
	RT_MUTEX mutex;
	RT_COND cond;
	int isFull(int buffId);
	int isEmpty(int buffId);

};

#endif /* DOUBLE_BUFFER_H_ */
